﻿<?php
require_once "config.php";
require_once "dbconfig.php";
require_once "tab.inc.php";	
function getUserInfo($apiKey,$sk,$uid){
	$url = "http://api.xiaonei.com/restserver.do?format=JSON&api_key=".$apiKey
			."&method=xiaonei.users.getInfo&session_key=".urlencode($sk)
			."&v=1.0&fields=name,sex,headurl,work_history,university_history&uids=".$uid;
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$rt = curl_exec($ch);
	curl_close($ch);
	$temp = htmlspecialchars($rt);
	$xmlHelper = new XMLHelper($temp);
	return $xmlHelper->getXMLNodeValue("name",false);
}
$tab = "feedback";
$method;
if($_POST["method"]){
	$method = $_POST["method"];
}
if($method=="feedback"){
  $feedback = $_POST['content'];
  $feedback = addslashes($feedback);
  $username = $_POST['userName'];
  $sqlInsert = "insert into app_feedback(feedback,username,user_id) values('".$feedback."','".$username."','".$uid."')";
  $flag = mysql_db_query($database, $sqlInsert);
}else{
	$userName = getUserInfo($apiKey,$sk,$uid);
}

$sqlQuery = "select * from app_feedback";
$feedbacks = mysql_db_query($database, $sqlQuery);

?>
<div style="margin:40px;">
   <h3>请把你的建议、或者特殊要求写在这里</h3>
   <form action="feedback.php" method="post">
   <input type="hidden" name="method" value="feedback"/>
   <input type="hidden" name="userName" value="<?php echo $userName;?>"/>
   <input type="hidden" name="user_id" value="<?php echo $uid;?>"/>
   <table>
      <tr><td>
      	<textarea name="content" cols="40" rows="4"></textarea>
      </td></tr>
      <tr><td><input type="submit" name="提交" value="提交"/></td></tr>
  </table>
   </form>
    <div style="float:left;margin:5px;width:600px;border:1px solid #e5f0f8;">
	 <?
        while($feedback = mysql_fetch_object($feedbacks)){
      ?>
	  <div style="margin:1px;border-bottom:1px #ccc dashed;">
	     <span style="color:#FF6600;font-size:18px;"><? echo $feedback->username;?></span> 留言:&nbsp;&nbsp;<span style="color:#FF6600;font-size:18px;"><?php echo stripslashes($feedback->feedback);?></span>
	  </div>
      <? }?>
	</div>
</div>
<?php 
	mysql_close();
?>	﻿